﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace PasswordProvider.ObjectModel
{
    public class GenericSite : Site
    {
        public GenericSite() { }

        public GenericSite(string name, string description)
            : base(name, description)
        {
        }

        #region Public Properties

        [DataMember]
        public EncryptedValue Data
        {
            get 
            { 
                if(_data == null)
                    _data = new EncryptedValue();
                return _data; 
            }
            set
            {
                _data = value;
                if (_data != null)
                    _data.PropertyChanged += delegate { OnPropertyChanged("Data"); };
            }
        } private EncryptedValue _data;

        [DataMember]
        public LogOnSite Website
        {
            get;
            set;
        }

        #endregion

        #region Overrides

        public override EncryptedValue PrimaryEncryptedValue
        {
            get { return Data; }
        }

        internal override string WriteExportString(SecurityManager securityManager, bool decryptAll)
        {
            StringBuilder builder = new StringBuilder(Name);

            builder.Append("\nDescription:\n ");
            builder.Append(Description);
            builder.Append("\nData: ");
            builder.Append(decryptAll ? securityManager.GetValueDecrypted(Data, false).UnprotectedString : "************");
            builder.Append("\n");

            return builder.ToString();
        }

        internal override Site Clone()
        {
            GenericSite clone = new GenericSite();
            clone.Copy(this);
            return clone;
        }

        internal override void Copy(Site site)
        {
            base.Copy(site);
            GenericSite generic = (GenericSite)site;
            generic.Data = this.Data;
            generic.Website = this.Website;
        }

        #endregion

    }
}
